<template>
	<view>
		<view class="personBg">
			<image class="personBgImage" src="/static/personBg.png"></image>
		</view>
		<view style="padding-top: 180px;">
			<view class="personAvator">
				<image @click="choose()" class="image-head" :src="avator"></image>
			</view>
			<view class="whiteCircleBg">
				<view style="padding-top: 70px;">
					<view class="inputContent1 marginTop marginLeft marginRight">
						<input class=" padding bigEmpty" v-model="name" maxlength="300" placeholder="输入合集名称" />
					</view>
					<view class="inputContent marginTop marginLeft marginRight">
						<textarea v-model="content" maxlength="300" placeholder="这个人很懒什么也没留下。" />
					</view>

				</view>

			</view>

			<button type="primary" class="marginTop3 marginLeft marginRight" @click="updateInfo()">确认</button>

		</view>
	</view>
</template>
<script>
	import request from '/common/request.js';
	export default {
		data() {
			return {
				avator: "",
				name: "",
				content: "这个人很懒什么也没留下。"

			}
		},

		onReady: function() {
			this.name = uni.getStorageSync("name");
			this.avator = uni.getStorageSync("avator");
			this.content = uni.getStorageSync("info");
		},
		onLoad() {
			this.requestInfo();
		},
		onUnload() {

		},

		methods: {

			updateInfo() {
				const url = getApp().globalData.apiUrl + "/api/v1/user/";
				const that = this;
				console.log()
				uni.request({
					url: url,
					data: {
						avator: this.avator,
						name: this.name,
						info: this.content
					},
					method: 'PUT',
					header: {
						'Content-Type': 'application/json',
						'satoken': uni.getStorageSync("token")
					},
					success: (res) => {

						console.log(res)
						if (res.data.code == 0) {
							uni.showToast({
								icon: 'success',
								title: "修改成功"
							})

						} else {
							uni.showToast({
								icon: 'error',
								title: res.data.message
							})
						}

					}
				});

			},

			choose() {
				const that = this;
				uni.chooseImage({

					count: 1, //上传的最大图片数量

					sizeType: ['compressed'], //压缩图片

					sourceType: ['camera', 'album'], //相机或图库

					success: res => {

						//选择成功的回调函数，res为选择的文件路径信息

						console.log(res.tempFilePaths)
						const url = getApp().globalData.apiUrl1 + "/api/v1/file/upload";


						uni.uploadFile({
							url: url,
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {}, //其它上传参数
							// header: {
							// 	"token": uni.getStorageSync('Token')
							// },
							success: (res) => {
								console.log(res)
								const data = JSON.parse(res.data);
								that.avator = data.data;
								console.log(that.avator)
								console.log(data)
							},
							fail: error => {
								that.enableUpdate = true;
								uni.showModal({
									title: '网络中断，上传失败',
									content: "请重试",
									showCancel: false
								});
								uni.hideLoading();
							},
							complete: () => {}
						});

					}

				});
			},

			requestInfo() {
				const url = getApp().globalData.apiUrl + "/api/v1/user/mine";
				const that = this;
				request(url, "GET", {}, uni.getStorageSync("token"))
					.then(function(res) {
						console.log('返回正确回调', res)
						if (res.code == 0) {
							uni.setStorageSync("token", res.data.token)
							uni.setStorageSync("name", res.data.name)
							uni.setStorageSync("info", res.data.info)
							uni.setStorageSync("avator", res.data.avator)
							uni.setStorageSync("level", res.data.level)
							uni.setStorageSync("vipName", res.data.vipName)
							uni.setStorageSync("vipNum", res.data.vipNum)
							uni.setStorageSync("vipTime", res.data.vipTime)
							uni.setStorageSync("productNum", res.data.productNum)
							uni.setStorageSync("fansNum", res.data.fansNum)
							uni.setStorageSync("commentNum", res.data.commentNum)
							uni.setStorageSync("loveNum", res.data.loveNum)
							uni.setStorageSync("fucusNum", res.data.fucusNum)
							uni.setStorageSync("sameProductNum", res.data.sameProductNum)
							that.name = uni.getStorageSync("name");
							that.avator = uni.getStorageSync("avator");
							that.content = uni.getStorageSync("info");
							

						}
					}, function(err) {
						console.log('返回错误回调', err)
					})
			}






		}
	}
</script>

<style>
	@import url("/common/uni.css");

	.bgSeleted {
		color: #FFFFFF;
		border-radius: 40rpx;
		background-color: #000000;
	}

	.button16WhiteText {
		font-size: 16px;
		font-weight: normal;
		line-height: 20px;
		letter-spacing: 0px;
		color: #FFFFFF;
	}


	.center {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.personBg {
		height: 200px;
		position: absolute;
		width: 100%;
		z-index: -1;
	}

	.personBgImage {
		position: absolute;
		width: 100%;
		z-index: -1;
	}

	.whiteCircleBg {

		background-color: #fff;
		border-radius: 8rpx;
	}




	.personAvator {

		z-index: 100;
		position: absolute;
		width: 100%;
		margin: -30px 0px 0px 0px;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.personAvator1 {
		border-radius: 50px 50px 50px 50px;
		background-color: white;
		padding: 4px;
		width: 100px;
		height: 100px;
	}
</style>